﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System.IO;
public class UIManager : MonoBehaviour
{
    public static UIManager instance = null;
    private void Awake()
    {
        instance = this;
    }
    /// <summary>
    /// 存放uiType(ui名字)和ui面板的字典
    /// </summary>
    public  Dictionary<string, UIBase> uiTypePanelDic = new Dictionary<string, UIBase>();

   /// <summary>
   /// 将UI面板添加到字典中
   /// </summary>
   /// <param name="ui"></param>
    public void Add(UIBase ui)
    {
        if (uiTypePanelDic.ContainsKey(ui.uiType)) return;
        
        uiTypePanelDic.Add(ui.uiType, ui);

    }


    public void ReMove(UIBase ui)
    {
        if (!uiTypePanelDic.ContainsKey(ui.uiType)) return;

        uiTypePanelDic.Remove(ui.uiType);
    }


    public UIBase GetUIByUIType(string uiType)
    {
        UIBase ui = null;
        if (uiTypePanelDic.ContainsKey(uiType))
        {
            ui = uiTypePanelDic[uiType];
        }
        return ui;
    }

    /// <summary>
    /// 弹出提示框
    /// </summary>
    /// <param name="content"></param>
    public void ShowTips(string content)
    {
        TipPanel tip = GetUIByUIType(UIType.TipPanel) as TipPanel;
        tip.ShowTip(content);
    }
    
    /// <summary>
    /// 显示任意一个面板
    /// </summary>
    /// <param name="uitype"></param>
    public void ShowPanel(string uitype)
    {
        UIBase ui = GetUIByUIType(uitype);
        ui.ShowUI();
    }


    /// <summary>
    /// 影藏任意UI
    /// </summary>
    /// <param name="uitype"></param>
    public void HidePanel(string uitype)
    {
        UIBase ui = GetUIByUIType(uitype);
        ui.HideUI();
    }

    //private AlarmCenterPanel alarm;
    //public void SpwanAlarmItem(string alarmType, string alarmInfo)
    //{
    //    if (alarm == null)
    //    {
    //        alarm = (AlarmCenterPanel)GetUIByUIType(UIType.AlarmCenterPanel);
    //    }


    //    if (alarm == null)
    //    {
    //        Debug.Log("脚本为空");
    //    }
    //   // Debug.Log(alarm.name);
    //    alarm.SpwanAlarmItem(alarmType, alarmInfo);

    //}

    //public void CancleAlarm(string alarmInfo)
    //{
    //    if (alarm == null)
    //    {
    //        alarm = (AlarmCenterPanel)GetUIByUIType(UIType.AlarmCenterPanel);
    //    }
    //    alarm. CancleAlarmItem(alarmInfo);
    //}
}
